package com.itheima.controller;

import com.itheima.constant.MessageConstant;
import com.itheima.entity.Result;
import com.itheima.health.pojo.CheckGroup;
import com.itheima.service.CheckGroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;

/*
    检查组的控制器
 */
@RestController
@RequestMapping("/checkgroup")
public class CheckGroupController {

    @Autowired
    private CheckGroupService cs ;

    @RequestMapping("/add")
    public Result add(@RequestBody CheckGroup checkGroup , int [] checkitemIds){
        System.out.println(checkGroup);
        System.out.println(Arrays.toString(checkitemIds));

        //1. 调用Service干活
        int row = cs.add(checkGroup, checkitemIds);

        //2. 判定
        Result result = null;
        if(row >0 ){
            result = new Result(true , MessageConstant.ADD_CHECKGROUP_SUCCESS);
        }else{
            result = new Result(false , MessageConstant.ADD_CHECKGROUP_FAIL);
        }

        return result;
    }
}
